﻿using System;
using System.Collections.Generic;
using System.Web;
using System.Text;

namespace MyAjax
{
    /// <summary>
    /// Summary description for SubTreeHandler
    /// </summary>
    public class SubTreeHandler : IHttpHandler
    {

        public void ProcessRequest(HttpContext context)
        {
            string nodeID= context.Request["nodeid"].ToLower();
            if (nodeID.EndsWith("ajax"))
            {
                nodeID = nodeID.Substring(0,nodeID.LastIndexOf("ajax"));
            }
            StringBuilder sb= new StringBuilder();
            
            sb.AppendFormat("<li id='{0}'><input id=\"cbx{0}\" type=\"checkbox\"/><span>Tree Node{0}</span>",nodeID+"|1");
            sb.Append("<ul class=\"ajax\">");
            string ajaxID=  nodeID + "|1ajax";
            sb.AppendFormat("<li id='{0}'>",ajaxID);
            string url = string.Format("url:SubTreeHandler.ashx?nodeid={0}", ajaxID); 
            sb.Append("{");
            sb.Append(url);
            sb.Append("}");
            sb.Append("</li>");
            sb.Append("</ul>");
            sb.Append("</li>");
            context.Response.ContentType = "text/plain";
            context.Response.Write(sb.ToString());
        }

        public bool IsReusable
        {
            get
            {
                return false;
            }
        }
    }
}